#ifndef SKIPLIST_H
#define SKIPLIST_H

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAX_LEVEL 16 //最大层级
#define PROBABILITY 0.5 //层数增长概率（50%）

typedef struct SkipListNode
{
    void *key;
    void *value;
    struct SkipListNode **level_next;// 指针数组：level_next[i]指向第i层的下一个节点
}SkipListNode;

typedef struct SkipList
{
    short max_level;//当前跳表的最大层数
    struct SkipListNode *head;// 表头节点（贯穿所有层）
}SkipList;

//为了适配所有的类型，传参时传二级指针
//比如int*和char*，为了统一，取二级指针后就都是void*了
typedef int (*skiplist_compare)(void *key1,void *key2);
extern skiplist_compare g_compare_skiplist;

SkipList* skiplist_init();
int skiplist_insert(SkipList* slist,void *key,void *value);
int skiplist_modify(SkipList* slist,void *key,void *value);
int skiplist_delete(SkipList* slist, void *key);
void* skiplist_search(SkipList* slist, void *key);

#endif